package model;

import model.Login_Servlet;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class Login {
    //koneksi jdbc


    private String jdbcURL = "jdbc:mysql://localhost:3306/rplo";
    private String user = "root";
    private String password = "";
    private Connection connection = null;

    public Login() {
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            connection = DriverManager.getConnection(jdbcURL, user, password);
        } catch (Exception ex) {
            System.out.println("message: " + ex.getMessage());
        }
    }

    public boolean isConnected() {
        if (connection != null) {
            return true;
        } else {
            return false;
        }
    }

    public boolean getClosed() {
        if (isConnected()) {
            try {
                connection.close();
                connection = null;
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
            return true;
        } else {
            return false;
        }
    }

    public String getJdbcURL() {
        return jdbcURL;
    }

    public void setJdbcURL(String jdbcURL) {
        this.jdbcURL = jdbcURL;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Connection getConnection() {
        return connection;
    }

    public void setConn(Connection connection) {
        this.connection = connection;
    }
    
    //Proses Login
    public ResultSet login(String username, String password) throws SQLException {

        Statement statement = connection.createStatement();
        String query = "select username,password from stafflogin where username='" + username + "'and password= '" + password + "'";
        System.out.println(username);
        System.out.println(password);
        System.out.println(query);
        ResultSet rest = statement.executeQuery(query);
        return rest;
    }
    
    
}
